<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		memberGetdev
	} from '@/api/index';
	import {
		reactive
	} from "vue";
	import {
		ref
	} from "vue";
	import {
		validateEnterpriseAccountApi
	} from "@/api/reserve";
	//
	const typeList = ref(["企业账户绑定"]);
	const curType = ref(0);

	onLoad((options) => {
		getDev()
		if (typeof options.type === "undefined") {
			uni.showToast({
				title: "初始化失败",
				icon: "none",
			});
			setTimeout(() => {
				uni.navigateBack(-1);
			}, 500);
			return;
		}
		// curType.value = Number(options.type);
	});


	const dev_type=ref(-1)
	const getDev=()=>{
		memberGetdev().then(res=>{
			dev_type.value=res.val
			if(res.val==1){
				typeList.value=[ "卡密预约","企业账户绑定"]
			}
			console.log(res)
		})
	}
	const formData = reactive({
		number: "",
		password: "",
	});
	const jumpPhone = () => {
		uni.navigateTo({
			url: "/pages/reserve/bind_phone/index"
		})
	}
	const submit = async () => {
		if (!formData.number || !formData.password) {
			uni.showToast({
				title: "请填写完整的信息",
				icon: "none",
			});
			return;
		}
		try {
			validateEnterpriseAccountApi({
				loginaccount: formData.number,
				loginpassword: formData.password,
			}).then(res => {
				uni.showToast({
					title: '绑定成功',
				})
				setTimeout(() => {
					uni.navigateBack(-1);
				}, 1000);
			}).catch(err => {
				if(err.message.includes("账号或密码不正确")){
					uni.showModal({
						content: "请拨打热线400-605-6596 进行预约",
						showCancel: false
					})
				}
				console.log(err)
			})

		} catch (error) {
			console.error('validateEnterpriseAccountApi error', error);
		}
	};
</script>

<template>
	<view class="app-bind">
		<view class="type-wrapper">
			<text :class="curType === index ? 'type-active' : ''" v-for="(item, index) in typeList" :key="index"
				@click="curType = index">{{ item }}</text>
		</view>

		<input class="form-input" placeholder="请输入体检人身份证号/护照号" v-model="formData.number" />
		<input class="form-input" type="password" placeholder="密码为身份证号/护照号后4位" v-model="formData.password" />
		<view class="form-button" @click="submit">
			<text>去预约</text>
		</view>
		<!-- v-if="curType === 1" -->
		<!-- <text class="phone-text" @click="jumpPhone()">手机号验证</text> -->

		<text class="tip-title">预约说明</text>
		<view class="tip-content">
			<!-- <text>进入APP首页 → 点击【我的】→ 选择【绑定医保卡】<br /><br />
				将实体医保卡置于光线充足处，对准屏幕扫码框<br />
				📌 提示：若为电子医保卡，可直接点击“同步电子医 保凭证”<br /><br />
				输入医保卡密码（默认密码或已修改的个人密码）<br /><br />
				完成人脸识别验证 → 点击【确认绑定】</text> -->
			<text>
				1.输体检人身份证号,密码为身份证号后4位\n
				2.如持有护照,输体检人护照号,密码为护照号后4位\n
				3.如手机号修改或其他原因导致无法登录可以联系合皋客服进行预约,电话：400-605-6596\n
			</text>
		</view>
	</view>
</template>

<style src="./style.scss" scoped />